#pragma warning(disable:4786)

#include <cstdio>
#include <vector>
#include <string>
#include<fstream>
#include<iostream>
#include<cstring>
#include<malloc.h>
#include<algorithm>
#include<deque>

//#include <windows.h>
#include <process.h>


using namespace std; 


#define DATATYPEFILENAME "datatype.dat"
#define FHFILENAME  "fh.dat"


#define EXTFILENAME           ".mdf"
#define EXTDBTFILENAME        ".dbt"
#define FILLVALUE '\0'

#define BINFILELENMAX    4294967295

#define BEGIN    0
#define TRUE     1
#define FALSE    0

//#define CString  string;

const int CURRENTVER=1204;//2009-08-13MODIFY

const int RWMAX=3072;

const short READ=0;
const short WRITE=1;


const short  BUFFERMAX=3072;
const  BUFFERMAX1=3145728;


const short ERRO1=-100;
const short ERRO2=-2;
const short ERRO3=-3;
const short ERRO4=-4;
const short ERRO5=-5;
const short ERRO6=-6;
const short ERRO7=-7;
const short ERRO8=-8;
const short ERRO9=-9;
const short ERRO10=-10;
const short ERRO11=-11;
const short ERRO12=-12;
const short ERRO13=-13;
const short ERRO14=-14;
const short ERRO15=-15;
const short ERRO16=-16;
const short ERRO17=-17;
const short ERRO18=-18;
const short ERRO19=-19;
const short ERRO20=-20;
const short ERRO21=-21;
const short ERRO22=-22;
const short ERRO23=-23;
const short ERRO24=-24;
const short ERRO25=-25;
const short ERRO26=-26;
const short ERRO27=-27;
const short ERRO28=-28;
const short ERRO29=-29;
const short ERRO30=-31;
const short ERRO31=-32;
const short ERRO32=-33;
const short ERRO33=-34;
const short ERRO34=-35;
const short ERRO35=-36;
const short ERRO36=-37;
const short ERRO37=-38;
const short ERRO38=-40;
const short ERRO39=-41;
const short ERRO40=-42;
const short ERRO41=-43;
const short ERRO42=-44;
const short ERRO43=-45;
const short ERRO44=-46;
const short ERRO45=-47;
const short ERRO46=-48;
const short ERRO47=-49;
const short ERRO48=-50;
const short ERRO49=-51;
const short ERRO50=-52;
const short ERRO53=-53;
const short ERRO54=-54;
const short ERRO55=-55;
const short ERRO56=-56;
const short ERRO57=-57;
const short ERRO58=-58;
const short ERRO59=-59;
const short ERRO60=-60;
const short ERRO61=-61;
const short NULLDATABASE=0;





const short CHARID=1;
const short INTID=2;
const short SHORTINTID=3;
const short BOOLID=4;
const short DATAID=5;
const short TEXTID=6;
const short IMAGEID=7;
const short BINID=8;
const short FLOATID=9;
const short BINARYID=10;
const short BINFILEID=11;


const short MAIN=1;
const short FILL=2;
const short NOFILL=3;


const short NOMODIFY=1;
const short MODIFY=2;
const short ADD=3;

const short DENYU=1;
const short DAYU=2;
const short XIAOYU=3;
const short BUTENGYU=4;
const short DATENGYU=5;
const short XIAOTENGYU=6;


const short iBinFileBuffersMaxCount=1000;//文件类型缓冲区最大块数
const unsigned int iBinFileBuffersMaxSize=614400;//文件类型缓冲区每块最大字节数

/*    TRUE:线程成功结束。线程完成任务正常退出。
	2:   写缓冲区溢出。
	3:   读缓冲区溢出。
	4:   写缓冲区缺数据。
	5:   读缓冲区缺数据。
	-1:  写数据库文件错误，线程异常退出。
	-2:  读数据库文件错误，线程异常退出。
	-3:  写缓冲区超过一定时间一直没有数据，线程认为异常退出。可能是网络出现异常。
	-4:  读缓冲区超过一定时间超过最大值，线程认为异常退出。可能是网络出现异常。
	-5:  读缓冲区数据长度校验错误
	-6:  已有线程在运行
	-7:  线程已异常终止
	-8:  字段名不一致
	-9： 字段数据长度不一致
	-10: 不在添加状态，请运行AddNew()函数
*/

const short  WRITEBUFFEROVERFLOW=2;
const short  READBUFFEROVERFLOW=3;
const short  WRITEBUFFERNULL=4;
const short  READBUFFERNULL=5;
const short  WRITEFILEERRO=-1;
const short  READFILEERRO=-2;
const short  WRITEBUFFERNULLERRO=6;
const short  READBUFFERNULLERRO=7;
const unsigned long   BUFFERNULLMAX=1000;
const short  BUFFEROVERFLOW=5000;
const short  READBUFFERLENERRO=-5;
const short  RUNING=-6;
const short  ERROSTOP=-7;
const short  FILEDERRO=-8;
const short  BINFILELENERRO=-9;
const short  BINFILEADDFLAGERRO=-10;
const short  CREATETHREADERRO=-11;


const short FHCOUNT=6;
const short TYPENAMELEN=10;
const short FIELDLEN=50;
const short TYPDMAX=11;
const short MAXPATH=512;
typedef  unsigned char SHORTINT;
typedef  char     TCHAR;
typedef  char*    PCHAR;
typedef  char     CHAR;

typedef  float    FLOAT;

typedef const char*  CPCHAR;

typedef unsigned int  BINFILE;//用于文件类型字段2009-06-27add

typedef long (__stdcall* FDPROC)(INT,PCHAR,void*);


typedef  int         INT;
typedef  short  int  SINT;
typedef  long    DATA;
typedef  float   FLOAT;
typedef  bool    SBOOL;
typedef  int     BOOL;
typedef  unsigned int  UINT;


struct DATATYPEDEF
{
	SHORTINT SId;
	TCHAR TTypeName[TYPENAMELEN];
	TCHAR TCtype[TYPENAMELEN];
};//数据类型

struct FIELDDEF
{
	SHORTINT SId;
	SHORTINT mainflag;
	SINT SFieldMaxSize;//表示字段长度
	TCHAR TFieldName[FIELDLEN];
};//字段定义

struct FILEDSTATION
{
	TCHAR TFieldName[FIELDLEN];
	int iTop;
	int SFieldMaxLen;
};//字段位置定义


struct DBFFILESTRUCT
{
	INT IDataCount;//记录个数
	INT IDataSize;//记录字节大小
	INT IFiledCount;//字段个数
	INT IEdition;//版本号
};//数据库文件结构


struct BINARY
{
	INT Itop;
	INT Ilen;
};


struct TEXT
{
	TCHAR *Buffer;
	int   Len;
};

struct IMAGE
{
	TCHAR *Buffer;
	int   Len;
};


struct BIN
{
	TCHAR *Buffer;
	int   Len;
};

struct  FH
{
	int ID;
	char f[6];
};
	
struct PIBINFILPAR
{
	PCHAR Filed;
	BINFILE Len;
	
};


